package cn.edu.hqu.javaee.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;


import lombok.Data;

@Data
@Entity
@Table(name="Taco_Order")
public class Order {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	private Date placedAt;
	 @NotBlank(message="Name is required")
	  private String name;
	  @NotBlank(message="number is required")
	  private String number;
	  @NotBlank(message="year is required")
	  private String year;
	  @NotBlank(message="major is required")
	  private String major;
	  @NotBlank(message="college code is required")
	  private String college;
	@ManyToMany(targetEntity=Taco.class)
	private List<Taco> tacos=new ArrayList<>();
	public void addDesign(Taco design) {
		this.tacos.add(design);
	}
	@PrePersist
	void placeAt() {
		this.placedAt=new Date();
	}
}
